<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
           类中写constructor表示是构造函数，在使用new实例化对象的时候会调用该函数
           如果内部不写构造函数定义为空 
         */
        class Animal {}

        class Person { 
            constructor () { 
                console.log('person not')
            }
        }

        class Vegetable { 
            constructor () {
                this.color = 'origin'
            }
        }

        let a = new Animal()

        let p = new Person() // 输出person not

        let v = new Vegetable()
        console.log(v.color) // origin 

        /*
           如果不需要向构造函数传参，实例化时类名后的括号可以不写 
         */
        class Person1 {
            constructor (name) {
                console.log('arguments输出:',arguments[0])
                this.name = name || null
            }
        }

        let p1 = new Person1 
        console.log(p1.name) // null

        let p2 = new Person1()
        console.log(p2.name)

        let p3 = new Person1('xiaomi')
        console.log(p3.name) // 小米

        /* 相当于定义了一个类 */
        function test () { 

        }
        test.age = 12
        console.log(test.age) //
        
        class test1 {}
        test1.age = 12
        console.log(test1.age)

        /* 类相当于特殊的函数 */
        class test2 {
            constructor() {}
        }
        console.log(typeof test2) // function

        const t = new test2()
        console.log(t instanceof test2) // true
        console.log(t instanceof test2.constructor) // false
        
    </script>
</body>
</html>